{include file='public/head'}
<style>
    .attachment{
        color: #1E9FFF;
    }
    .attachment_del{
        color: #FF5722;
    }
</style>
<body>
<div class="x-body">
    <form class="layui-form" id='mainForm' method="post" action="recharge">

        <div class="layui-form-item">
            <label class="layui-form-label"><b style="color: red">*</b>充值金额￥</label>
            <div class="layui-input-block">
                <input type="number" id="money" name="money" lay-verify="required" min="1"
                       autocomplete="off" placeholder="请输入充值金额" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><b style="color: red">*</b>充值日期</label>
            <div class="layui-input-block">
                <input type="text" id="execdate" name="execdate" lay-verify="required" value="{$date}"
                       autocomplete="off" placeholder="请选择充值日期" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><b style="color:red">*</b>充值原因</label>
            <div class="layui-input-block">
                <select name="rechar_id" id="rechar_id" lay-verify="required" lay-filter="rechar_id">
                    {volist name="rechar" id="vo"}
                    <option value="{$vo.id}">{$vo.reason}</option>
                    {/volist}
                </select>
                <input type="hidden" id="rechar" name="rechar" value="{$rechar[0]['reason']|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">上传凭证</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="upload_file">
                    上传凭证
                </button>
                <div id="attachment_box">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 15px">
            <div>
                <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
                <input type="hidden" id="purpose" name="purpose" value="{$Think.get.purpose}">
                <input type="hidden" id="type" name="type" value="{$Think.get.type}">
                <button style="width: 100%" class="layui-btn" lay-submit="" lay-filter="toSubmit">提交保存</button>
            </div>
        </div>

    </form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
    $(document).ready(function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var upload = layui.upload;

        form.on('select(rechar_id)', function (data) {
            $("#rechar").val(data.elem[data.elem.selectedIndex].text);
        });

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_file' //绑定元素
            , url: 'upload_voucher.html' //上传接口
            , accept: 'images'
            , field: 'voucher'
            , acceptMime:'image/*'
            , multiple:true
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(0, {shade: [0.3, '#000']}); //上传loading
            }
            ,done: function(data){
                // console.log(data);
                //上传完毕回调
                if(data.res){
                    layer.msg(data.msg);
                    layer.closeAll('loading');
                    var html = '<div>';
                    html += '<a class="attachment" target="_blanck" href="' + data['files']['path'] + '">' + data.files.original + '</a>';
                    html += '<input name="name[]" type="hidden" id="name[]" value="' + data.files.name + '"/>';
                    html += '<input name="path[]" type="hidden" id="path[]" value="' + data.files.path + '"/>';
                    html += '<input name="size[]" type="hidden" id="size[]" value="' + data.files.size + '"/>';
                    html += '<input name="postfix[]" type="hidden" id="postfix[]" value="' + data.files.postfix + '"/>';
                    html += '<input name="original[]" type="hidden" id="original[]" value="' + data.files.original + '"/>';
                    html += '<a class="attachment_del" href="javascript:;">[删除]</a><br></div>';
                    $("#attachment_box").append(html);
                }else{
                    layer.msg(data.msg);
                    layer.closeAll('loading');
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //删除上传文件
        $(document).on("click", ".attachment_del", function () {
            $(this).parent().remove();
        })

        //执行一个laydate实例
        laydate.render({
            elem: '#execdate' //指定元素
        });
        var options = {
            type: 'post',           //post提交
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                if (data.code == 0) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };

        // bind form using 'ajaxForm'
        $('#mainForm').ajaxForm(options).submit(function (data) {
        });
    });
</script>
</html>
